package com.javatip.project.Controller.getUserInfo.controller;

import com.javatip.common.utils.security.ShiroUtils;
import com.javatip.project.Controller.getUserInfo.service.IGetUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

//  获取用户角色
@Controller
@RequestMapping("/getUserRole")
@Slf4j
@Api(tags = "获取用户信息")
public class GetUserRoleController {

    @Autowired
    private IGetUserRoleService getUserRoleService;

    @ApiOperation(value = "判断当前用户是否为管理员")
    @GetMapping("/isAdmin")
    public ResponseEntity<Boolean> isAdmin() {
//        log.info("获取用户角色");
        Long currentUserId = ShiroUtils.getSysUser().getUserId();
        int userRole = getUserRoleService.getUserRole(currentUserId);
//        System.out.println("userRole="+userRole);
        if (userRole == 1) {
            return ResponseEntity.ok(true);
        } else {
        }
        return ResponseEntity.ok(false);
    }

    @ApiOperation(value = "获取当前用户id")
    @GetMapping("/getUserId")
    public ResponseEntity<Integer> getUserId() {
//        log.info("获取当前用户id");
        Long currentUserId = ShiroUtils.getSysUser().getUserId();
        return ResponseEntity.ok(Math.toIntExact(currentUserId));
    }
}
